function get_time()
{
    var d = new Date();
    return parseInt(d.getTime()/1000);
}

function read_time(seconds)
{
    var d = new Date();
    d.setTime(seconds * 1000);
    return d;
}

function write_time(y, m, d)
{
    var d = new Date(y, m - 1, d);
    return parseInt(d.getTime()/1000);
}

function post_create_task(name, duetime, remidertime, description, callback)
{
    pdata = {
        'name' : name,
        'duetime' : duetime,
        'remidertime' : remidertime,
        'description' : description
    };
    post_ajax_js(pdata, "/rpc/create/", callback);
}


function post_get_task(taskid, callback)
{
    pdata = {
        'task_id' : taskid
    };
    post_ajax_js(pdata, "/rpc/get/", callback);
}


function post_set_state(taskid, state, callback)
{
    pdata = {
        'task_id' : taskid,
        'state' : state
    };
    post_ajax_js(pdata, "/rpc/set/state", callback);
}

function post_list_owner_task(owner, callback)
{
    pdata = {
        'owner' : owner
    };
    post_ajax_js(pdata, "/rpc/list/owner", callback);
}

function post_commit_name(taskid, name, callback)
{
    pdata = {
        'task_id' : taskid,
        'name' : name,
    };
    post_ajax_js(pdata, "/rpc/commit/name", callback);
}

function post_commit_duetime(taskid, duetime, callback)
{
    pdata = {
        'task_id' : taskid,
        'duetime' : duetime
    };
    post_ajax_js(pdata, "/rpc/commit/duetime", callback);
}

function post_commit_remidertime(taskid, remidertime, callback)
{
    pdata = {
        'task_id' : taskid,
        'remidertime' : remidertime
    };
    post_ajax_js(pdata, "/rpc/commit/remidertime", callback);
}

function post_commit_all(taskid, name, duetime, remidertime, callback)
{
    pdata = {
        'task_id' : taskid,
        'name' : name,
        'duetime' : duetime,
        'remidertime' : remidertime
    };
    post_ajax_js(pdata, "/rpc/commit/all", callback);
}

function post_ajax_js(postdata, url, call_back_func)
{
    postdata['owner'] = 'spike';
    request = {
        'type' : "POST",
        'url' : url,
        'data' : {'postdata' : JSON.stringify(postdata)},
        'dataType' : 'json',
        'success' : call_back_func
    }
    $.ajax(request);
}
